const state = {
  baseInfo: localStorage.getItem('baseInfo')
    ? JSON.parse(localStorage.getItem('baseInfo'))
    : {}, // 当前系统baseInfo信息
  attrTable: localStorage.getItem('attrTable')
    ? JSON.parse(localStorage.getItem('attrTable'))
    : [], // 商品详情生成的attr明细表
  tableHead: localStorage.getItem('tableHead')
    ? JSON.parse(localStorage.getItem('tableHead'))
    : {} // 表头
};
const getters = {
  baseInfo: state => state.baseInfo,
  attrTable: state => state.attrTable,
  tableHead: state => state.tableHead
};
const mutations = {
  setTableHead(state, data) {
    localStorage.setItem('tableHead', JSON.stringify(data));
    state.tableHead = JSON.parse(localStorage.getItem('tableHead'));
  },
  setAttrTable(state, data) {
    localStorage.setItem('attrTable', JSON.stringify(data));
    state.attrTable = JSON.parse(localStorage.getItem('attrTable'));
  },
  setBaseInfo(state, data) {
    localStorage.setItem('baseInfo', JSON.stringify(data));
    state.baseInfo = JSON.parse(localStorage.getItem('baseInfo'));
  },
  clearBaseInfo() {
    localStorage.removeItem('baseInfo');
  }
};
const actions = {};

export default {
  state,
  getters,
  actions,
  mutations
};
